package com.learn.springmvc4.web;

import org.apache.commons.io.FileUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;

/**
 * Created by xuxiaobao on 2017/8/4.
 */
@Controller
public class AdviceController {

    @RequestMapping(value = "/advice")
    public void getSomeThing(HttpServletResponse response) {
        try {
            File file = FileUtils.toFile(new URL("http://bpic.588ku.com/back_pic/03/92/40/4957e29f80d8a4a.jpg!ww650"));
            FileInputStream stream = FileUtils.openInputStream(file);
            ServletOutputStream out = response.getOutputStream();
            byte[] b = new byte[1024];
            int count = 0;
            while ((count = stream.read()) != -1) {
                out.write(b, 0, count);
            }
            out.close();
            stream.close();
        } catch (IOException e) {
            System.out.println("exception");
        }
    }
}
